/**   
* @Title: FengKongShenHeView.java 
* @Package com.zjdiepu.www.manage.api.zpp.view 
* 
* @author zhangpp
* @date 2017年5月26日 下午1:41:53 
* @version V1.0   
*/
package com.zjdiepu.www.manage.api.zpp.view;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.io.FileReader;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.core.AbstractSysUser;
import com.zjdiepu.www.base.core.BaseException;
import com.zjdiepu.www.base.enums.status.BusiStatus;
import com.zjdiepu.www.base.enums.status.DpStatus;
import com.zjdiepu.www.base.enums.status.LessInformationStatus;
import com.zjdiepu.www.base.enums.status.PhoneStatus;
import com.zjdiepu.www.base.enums.type.BusinessExtrasCodeType;
import com.zjdiepu.www.base.enums.type.BusinessExtrasType;
import com.zjdiepu.www.base.enums.type.DataDicType;
import com.zjdiepu.www.base.enums.type.ModeIDType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.common.util.CollectionInitUtil;
import com.zjdiepu.www.common.util.ZhppDateUtil;
import com.zjdiepu.www.commpent.ViewScopeControllerHelper;
import com.zjdiepu.www.dao.dz.DzPickCarMapper;
import com.zjdiepu.www.dao.fk.FkAuditListMapper;
import com.zjdiepu.www.dao.icbc.OtherLoanLossProvisionMapper;
import com.zjdiepu.www.dao.yw.YwFeesMapper;
import com.zjdiepu.www.dao.yw.YwFeesSubMapper;
import com.zjdiepu.www.dao.yw.YwFundApplyMapper;
import com.zjdiepu.www.dao.yw.YwTransferMapper;
import com.zjdiepu.www.dao.zpp.PublicDao;
import com.zjdiepu.www.ibiz.base.IDpBaseDataDictionaryService;
import com.zjdiepu.www.ibiz.cache.ICachedDictionaryService;
import com.zjdiepu.www.ibiz.cw.ICwIncomeExpensesItemService;
import com.zjdiepu.www.ibiz.cw.ICwRefundCarService;
import com.zjdiepu.www.ibiz.cw.ICwRemitAdjustbSubService;
import com.zjdiepu.www.ibiz.cw.ICwRemitCarService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessCarService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessExtrasService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessLoanService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessService;
import com.zjdiepu.www.ibiz.yw.IYwFeesSubService;
import com.zjdiepu.www.model.base.dto.DpBaseDataDictionary;
import com.zjdiepu.www.model.base.dto.SysUser;
import com.zjdiepu.www.model.base.ext.DpBaseDataDictionaryExt;
import com.zjdiepu.www.model.cw.dto.CwRefundCar;
import com.zjdiepu.www.model.cw.dto.CwRemitAdjustbSub;
import com.zjdiepu.www.model.cw.response.CwFundItem;
import com.zjdiepu.www.model.dz.dto.DzPickCar;
import com.zjdiepu.www.model.fk.dto.FkAuditList;
import com.zjdiepu.www.model.yw.dto.YwBusiness;
import com.zjdiepu.www.model.yw.dto.YwBusinessCar;
import com.zjdiepu.www.model.yw.dto.YwBusinessExtras;
import com.zjdiepu.www.model.yw.dto.YwBusinessLoan;
import com.zjdiepu.www.model.yw.dto.YwFees;
import com.zjdiepu.www.model.yw.dto.YwFundApply;
import com.zjdiepu.www.model.yw.dto.YwTransfer;
import com.zjdiepu.www.model.yw.response.YwBusinessDetail;
import com.zjdiepu.www.util.CachedEnums;
import com.zjdiepu.www.util.CommonUtil;
import com.zjdiepu.www.util.ExceptionHelper;

/**      
 * 项目名称：diepu-parent-manage   
 * 类名称：FengKongShenHeView   
 * 类描述：   
 * 创建人：zhangpp
 * 创建时间：2017年5月26日 下午1:41:53   
 * 修改人：zhangpp
 * 修改时间：2017年5月26日 下午1:41:53   
 * 修改备注：   
 * @version V1.0     
 */
@Controller
@RequestMapping(value= "FengKongShenHeView", produces="application/json;charset=UTF-8")
@Api(tags = {"作者：张鹏鹏，电话：15158822934"}, produces="application/json;charset=UTF-8")
public class FengKongShenHeView extends BaseController
{
	@Resource
	private PublicDao publicDao;
	
	@Resource
    private ViewScopeControllerHelper viewScopeControllerHelper;
	
	@Resource
    private ICachedDictionaryService cachedDictionaryService;
	
	@Resource
    private IYwBusinessService ywBusinessService;
	
	@Resource
	private FkAuditListMapper fkAuditListMapper;
	
	@Resource
	private YwFundApplyMapper ywFundApplyMapper;
	
	@Resource
	private YwFeesMapper ywFeesMapper;
	
	@Resource
	private YwFeesSubMapper ywFeesSubMapper;
	
	@Resource
    private IDpBaseDataDictionaryService dBaseDataDictionaryService;
	
	@Resource
    private IYwFeesSubService ywFeesSubService;
	
	@Resource
    private IYwBusinessExtrasService ywBusinessExtrasService;
	
	@Resource
	private ICwIncomeExpensesItemService cwIncomeExpensesItemService;
	
	@Resource
    private ICwRemitCarService cwRemitCarService;
	
	@Resource
	private IYwBusinessExtrasService iYwBusinessExtrasService;
	
	@Resource
	private ICwRemitAdjustbSubService cwRemitAdjustbSubService;
	
	@Resource
	private IYwBusinessLoanService ywBusinessLoanService;
	
	@Resource
	private YwTransferMapper ywTransferMapper;
	
	@Resource
	private IYwBusinessCarService ywBusinessCarService;
	
	@Resource
	private DzPickCarMapper dzPickCarMapper;
	
	@Resource
	private OtherLoanLossProvisionMapper otherLoanLossProvisionMapper;
	
	@Resource
	private ICwRefundCarService cwRefundCarService;
	

	/**
	* 财务审核
	*  @author  zhangpp
	*  @Title:  getCaiWuShenHeView  
	*    
	*  @param  @param model
	*  @param  @param busiId
	*  @param  @param replaceId
	*  @param  @param modeId
	*  @param  @return        设定文件  
	*  @return  String        返回类型  
	*  @version  V1.0
	*  @throws
	*/
	@RequestMapping(value = "getCaiWuShenHeView", method = RequestMethod.GET)
	public String getCaiWuShenHeView(Model model, String busiId,String replaceId,String modeId) 
	{
		if (StringUtils.isBlank(busiId)) 
		{
			ExceptionHelper.thow(ResultFlagType.PARAM_EMPTY);
		}
		
    	model.addAttribute("loanBank", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.REMIT_TYPE,"请选择..."));
    	
    	viewScopeControllerHelper.preparedNowTime(model);
    	YwBusinessDetail ywBusinessDetail = viewScopeControllerHelper.preparedBusiness(busiId, model);
    	if(ywBusinessDetail != null){
    		viewScopeControllerHelper.preparedYwFee(busiId, ywBusinessDetail.getCustomerId(), model);
    		viewScopeControllerHelper.preparedFundApply(busiId, ywBusinessDetail.getCustomerId(),null,false, model);
    		viewScopeControllerHelper.preparedRemitCar(busiId, ywBusinessDetail.getCustomerId(), model);
    	}
    	YwBusinessCar car = viewScopeControllerHelper.preparedCar(busiId,ywBusinessDetail.getCustomerId(), model);
    	if(car != null) 
    	{
    		viewScopeControllerHelper.preparedLoan(busiId, car.getId(), model, car.getCarType());
    	}
    	viewScopeControllerHelper.preparedCarModel(model);
    	
    	DpBaseDataDictionaryExt dpBaseDataDictionaryExt = new DpBaseDataDictionaryExt();
    	dpBaseDataDictionaryExt.setBaseWhere();
    	dpBaseDataDictionaryExt.withOutPage();
    	dpBaseDataDictionaryExt.setParentValue(DataDicType.FUND_ITEM.getCode());
    	dpBaseDataDictionaryExt.setAddedValue1("01"); //启用的明细
    	dpBaseDataDictionaryExt.setOrderSql("`VALUE`");
    	List<DpBaseDataDictionary> dpBaseDataDictionarys = dBaseDataDictionaryService.selectByExt(dpBaseDataDictionaryExt);
    	
    	DpBaseDataDictionaryExt depositItemExt = new DpBaseDataDictionaryExt();
    	depositItemExt.setBaseWhere();
    	depositItemExt.setRows(1);
    	depositItemExt.setParentValue(DataDicType.FUND_ITEM.getCode());
    	depositItemExt.setValue("35");
    	List<DpBaseDataDictionary> depositDataDictionaryItems = dBaseDataDictionaryService.selectByExt(depositItemExt);
    	if(CollectionUtils.isNotEmpty(depositDataDictionaryItems)) 
    	{
    		dpBaseDataDictionarys.add(depositDataDictionaryItems.get(0));
    	} 
    	else 
    	{
    		DpBaseDataDictionary dpBaseDataDictionary = new DpBaseDataDictionary();
    		dpBaseDataDictionary.setValue("35");
    		dpBaseDataDictionary.setName("征信押金");
    		dpBaseDataDictionary.setParentValue(DataDicType.FUND_ITEM.getCode());
    		dpBaseDataDictionarys.add(dpBaseDataDictionary);
    	}
    	depositItemExt.setBaseWhere();
    	depositItemExt.setRows(1);
    	depositItemExt.setParentValue(DataDicType.FUND_ITEM.getCode());
    	depositItemExt.setValue("01");
    	List<DpBaseDataDictionary> depositDataDictionaryItems_ = dBaseDataDictionaryService.selectByExt(depositItemExt);
    	if(CollectionUtils.isNotEmpty(depositDataDictionaryItems_)) 
    	{
    		dpBaseDataDictionarys.add(depositDataDictionaryItems_.get(0));
    	} 
    	else 
    	{
    		DpBaseDataDictionary dpBaseDataDictionary = new DpBaseDataDictionary();
    		dpBaseDataDictionary.setValue("01");
    		dpBaseDataDictionary.setName("按揭服务费");
    		dpBaseDataDictionary.setParentValue(DataDicType.FUND_ITEM.getCode());
    		dpBaseDataDictionarys.add(dpBaseDataDictionary);
    	}
    	
     	List<Map<String, Double>> fees = ywFeesSubService.countReceiveByBusiId(busiId, null);
    	
    	List<String> exludeKeys = Arrays.asList(new String[]{"01", "35"});
    	List<CwFundItem> fundItems = CollectionInitUtil.emptyList();
    	List<CwFundItem> fundItems_ = CollectionInitUtil.emptyList();
    	List<Map<String, Double>> remits = cwIncomeExpensesItemService.countReceiveByBusiId(busiId, null);
    	if(CollectionUtils.isNotEmpty(dpBaseDataDictionarys)) 
    	{
    		for(DpBaseDataDictionary dpBaseDataDictionary : dpBaseDataDictionarys) 
    		{
    			CwFundItem cwFundItem = new CwFundItem();
    			String key = dpBaseDataDictionary.getValue();
    			cwFundItem.setKey(key);
    			cwFundItem.setName(dpBaseDataDictionary.getName());
    			cwFundItem.setFeeCount(ViewScopeControllerHelper.getItem(fees, key));
    			cwFundItem.setRemitCount(ViewScopeControllerHelper.getItem(remits, key));
    			if(exludeKeys.contains(key))
    			{
    				fundItems_.add(cwFundItem);
    			} 
    			else
    			{
    				fundItems.add(cwFundItem);
    			}
    		}
    	}
    	model.addAttribute("fundItems", fundItems);
    	model.addAttribute("fundItems_", fundItems_);
    	
    	CwFundItem cwFundItem = new CwFundItem();
    	cwFundItem.setFeeCount(ViewScopeControllerHelper.countItems(fees, null));
    	cwFundItem.setRemitCount(ViewScopeControllerHelper.countItems(remits, null));
    	model.addAttribute("fundTotal", cwFundItem);
    	
    	String history = cwRemitCarService.queryHistoryByBusiId(busiId);
    	model.addAttribute("history", StringUtils.isBlank(history)?"-":(history.startsWith(",")?history.substring(1):history));
    	
    	//add by zzj 增加退提车款时间
    	CwRefundCar cwRefundCar= new CwRefundCar();
    	cwRefundCar.setBusiId(busiId);
    	cwRefundCar.setDpStatus(DpStatus.NORMAL.getCode());
    	cwRefundCar=cwRefundCarService.selectRefined(cwRefundCar);
    	model.addAttribute("cwRefundCar", cwRefundCar);
    	
    	SysUser sysUser =(SysUser)getCurrentUser();
    	viewScopeControllerHelper.preparedAllocation(sysUser.getOrgId(), model);
		
    	YwFundApply ywFundApply = new YwFundApply();
    	ywFundApply.setBusiId(busiId);
    	ywFundApply.setDpStatus(1);
    	ywFundApply = ywFundApplyMapper.selectRefined(ywFundApply);
    	model.addAttribute("ywFundApply", ywFundApply);
    	if(null != ywFundApply)
    	{
    		String dateFist = ZhppDateUtil.DateToString(ywFundApply.getDateFist(),ZhppDateUtil.SHORT_DATE_FORMAT);
    		model.addAttribute("dateFist", dateFist);
    	}    	
    	
    	YwFees ywFees = new YwFees();
    	ywFees.setBusiId(busiId);
    	ywFees.setDpStatus(1);
    	ywFees = ywFeesMapper.selectRefined(ywFees);
    	if(null != ywFees)
    	{
    		ywFees.setRebateType(cachedDictionaryService.getName(ywFees.getRebateType(), DataDicType.REBATE_TYPE));
    		ywFees.setTypeBalanceDisplay(cachedDictionaryService.getName(ywFees.getTypeBalance(), DataDicType.SETTLEMENT_TYPE));
    		model.addAttribute("ywFees", ywFees);
    	}
    	
    	model.addAttribute("busiId",busiId);
    	model.addAttribute("replaceId",replaceId);
    	model.addAttribute("modeId",modeId);
    	
    	//资金渠道
    	model.addAttribute("fund_channel", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.FUND_CHANNEL,"请选择..."));
    	
    	String sqlXmls = "select t.`name`,t.`value` from dp_base_data_dictionary t where t.parent_value = 'Fund_Channel' and t.`value` = 'zy' and t.dp_status = 1";
    	Map<String, String> mpas = publicDao.selectMapsSql(sqlXmls);
    	model.addAttribute("mpas",mpas);
    	
    	//特殊订单
	    YwBusinessExtras ywBusinessExtras = new YwBusinessExtras();
	    ywBusinessExtras.setDpStatus(DpStatus.NORMAL.getCode());;
	    ywBusinessExtras.setCodeExtras(BusinessExtrasCodeType.IS_SPECIAL_ORDER.getCode());
	    ywBusinessExtras.setTypeExtras(BusinessExtrasType.AUDIT.getCode());
	    ywBusinessExtras.setBusiId(busiId);
	    YwBusinessExtras ywBusinessExtras_ = ywBusinessExtrasService.selectRefined(ywBusinessExtras);
	    boolean isSpecialOrder = false;
	    if(null != ywBusinessExtras_) 
	    {
	       if("1".equals(ywBusinessExtras_.getValueExtras())) 
	       {
	         isSpecialOrder = true;
	       }
	    }
	    model.addAttribute("isSpecialOrder", isSpecialOrder);
	    
	    //如果订单的贷款银行是杭州工行（bank_loan =  ICBC），显示风险准备金相关信息，数据从 【other_loan_loss_provision】获取（dp_status = 1）
	    YwBusiness ywBusiness = ywBusinessService.selectById(busiId);
	    if(null != ywBusiness)
	    {
	    	sqlXmls = "select t.id,t.bank,t.instcode,t.accno,t.sub_accno,t.bal from other_loan_loss_provision t where t.bank = '"+ywBusiness.getBankLoan()+"' and t.dp_status = 1 and t.type_data = 3";
	    	List<Map<String, String>> otherLoanLossProvision = publicDao.queryWhereSql(sqlXmls);
	 	    model.addAttribute("otherLoanLossProvision",otherLoanLossProvision);
	    }
		return "fengKongShenHe/fkshCwshy_V1";
	}
	
	
	/**
	* 风控审核
	* @author zhangpp
	* @Title: getFengKongShenHelist 
	* 
	* @param @param model
	* @param @param busiId
	* @param @return    设定文件 
	* @return String    返回类型 
	* @version V1.0
	* @throws
	 */
    @RequestMapping(value = "getFengKongShenHelist", method = RequestMethod.GET)
    public String getFengKongShenHelist(Model model, String busiId,String replaceId,String modeId) 
	{
    	if(StringUtils.isBlank(busiId)) 
    	{
			ExceptionHelper.thow(ResultFlagType.PARAM_EMPTY);
		}
    	
    	model.addAttribute("carCategoryType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_CATEGORY,"请选择..."));
    	model.addAttribute("carColorType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_COLOR,"请选择..."));
    	
    	viewScopeControllerHelper.preparedNowTime(model);
    	YwBusinessDetail ywBusinessDetail = viewScopeControllerHelper.preparedBusiness(busiId, model);
    	YwBusinessCar car = viewScopeControllerHelper.preparedCar(busiId, null,model);
    	if(car != null) {
    		viewScopeControllerHelper.preparedLoan(busiId, car.getId(), model,car.getCarType());
    	}
    	if(ywBusinessDetail != null) {
    		viewScopeControllerHelper.preparedHistoryBusiness(ywBusinessDetail.getCustomerNo(), model);
    	}
    	
    	viewScopeControllerHelper.preparedRegin(model,null,null);
    	viewScopeControllerHelper.preparedCarModel(model);
    	viewScopeControllerHelper.preparedAttachmentEnum(model);
    	
    	
    	//查询待审批列表数据
    	FkAuditList fkAuditList = new FkAuditList();
    	fkAuditList.setStatusList(1);
    	fkAuditList.setBusiId(busiId);
    	fkAuditList.setModeId(modeId);
    	fkAuditList = fkAuditListMapper.selectRefined(fkAuditList);
    	
    	//判断操作人是否与当前的一致
    	if(null != fkAuditList && !("").equals(fkAuditList))
    	{
    		AbstractSysUser currentUser = getCurrentUser();
    		String id = currentUser.getId();
    		String name = currentUser.getName();
    		
    		String operatorId = fkAuditList.getOperatorId();
    		if(null == operatorId || ("").equals(operatorId))
    		{
    			fkAuditList.setOperatorId(id);
    			fkAuditList.setOperatorName(name);
    			fkAuditList.setAcceptDate(new Date());
    			fkAuditListMapper.updateByPrimaryKeySelective(fkAuditList);
    		}
    	}
    	
    	//查询业务信息表
    	YwBusiness ywBusinessVo = ywBusinessService.selectById(busiId);
    	model.addAttribute("ywBusinessVo",ywBusinessVo);
    	
    	model.addAttribute("busiId",busiId);
    	model.addAttribute("replaceId",replaceId);
    	model.addAttribute("modeId",modeId);
    	
    	//下拉选项
    	model.addAttribute("maritalStatus", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.MARITAL_STATUS,"请选择..."));
    	model.addAttribute("dealerLevel", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.DEALER_LEVEL,"请选择..."));
    	model.addAttribute("educationType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.EDUCATION,"请选择..."));
    	model.addAttribute("sexType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.SEX,"请选择..."));
    	model.addAttribute("loanType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LOAN_TYPE,"请选择..."));
    	model.addAttribute("loanBankType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LOAN_BANK,"请选择..."));
    	model.addAttribute("licencePlateType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LICENCE_PLATE_TYPE,"请选择..."));
    	model.addAttribute("carType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_TYPE,"请选择..."));
    	model.addAttribute("carPlaceType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_PLACE,"请选择..."));
    	model.addAttribute("loanMonthType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LOAN_MONTH,"请选择..."));
    	model.addAttribute("jobType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.ZHI_WEI,"请选择..."));
    	model.addAttribute("workAgeType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.WORK_AGE,"请选择..."));
    	model.addAttribute("carStatus", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_STATUS,"请选择..."));
    	model.addAttribute("carPurpose", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_PURPOSE,"请选择..."));
    	model.addAttribute("channelType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CHANNEL_TYPE,"请选择..."));
    	model.addAttribute("channelStatus", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CHANNEL_STATUS,"请选择..."));
    	
    	model.addAttribute("busiStatusNames", CachedEnums.getNames(BusiStatus.class));
    	model.addAttribute("phoneStatusNames", CachedEnums.getNames(PhoneStatus.class));
    	model.addAttribute("lessInformationStatusNames", CachedEnums.getNames(LessInformationStatus.class));
    	model.addAttribute("businessExtrasCodeTypeNames", CachedEnums.getNames(BusinessExtrasCodeType.class));
    	
    	
    	//风控审核 初审单初审
    	if(modeId.equals("M_csdcs"))
    	{
    		return "fengKongShenHe/fkshCsdcs";
    	}
    	
    	//风控审核 初审单终身
    	if(modeId.equals("M_csdzs"))
    	{
    		return "fengKongShenHe/fkshCsdzs";
    	}
    	
    	//风控审核 资审一审
    	if(modeId.equals("M_zsys"))
    	{
    		return "fengKongShenHe/fkshZsys";
    	}
    	
    	//风控审核 资审二审
    	if(modeId.equals("M_zses"))
    	{
    		return "fengKongShenHe/fkshZses";
    	}
    	
    	//风控审核 电审一审
    	if(modeId.equals("M_dscs"))
    	{
    		return "fengKongShenHe/fkshDsys";
    	}
    	
    	//风控审核 电审二审
    	if(modeId.equals("M_dsfs"))
    	{
    		return "fengKongShenHe/fkshDses";
    	}
    	
    	//风控审核 风控经理审核
    	if(modeId.equals("M_fkjlsh"))
    	{
    		return "fengKongShenHe/fkshFkjlsh";
    	}
    	
    	//风控审核 风控经理审核
    	if(modeId.equals("M_fkzjsh"))
    	{
    		return "fengKongShenHe/fkshFkzjsh";
    	}
    	
    	//风控审核 通融审批
    	if(modeId.equals("M_trsh"))
    	{
    		return "fengKongShenHe/fkshTrsh";
    	}
    	
    	//风控审核 绿色通道审核
    	if(modeId.equals("M_lstdsh"))
    	{
    		return "fengKongShenHe/fkshLstdsh";
    	}
    	
    	//风控审核 过户审核
    	if(modeId.equals("M_ghsh"))
    	{
    		return "fengKongShenHe/fkshGhsh";
    	}
    	
    	//风控审核 大额垫款审核
    	if(modeId.equals("M_dedksp"))
    	{
    		return "fengKongShenHe/fkshDedksp";
    	}
    	//风控审核 资料不齐
    	if(modeId.equals("M_zlbqsh"))
    	{
    		return "fengKongShenHe/fkshZlbqsh";
    	}
    	//稽核审核
    	if(modeId.equals("M_jhsc"))
    	{
    		return "fengKongShenHe/fkshJhsc";
    	}
    	//退押金催收审核
    	if(modeId.equals("M_tyjcssh"))
    	{
    		return "fengKongShenHe/fkshYjcssh";
    	}
    	//退押金续保审核
    	if(modeId.equals("M_tyjxbsh"))
    	{
    		return "fengKongShenHe/fkshTyjxbsh";
    	}
    	//代偿稽核审核
    	if(modeId.equals("M_dcjhsc"))
    	{
    		return "fengKongShenHe/fkshDcjhsc";
    	}
    	//新车提车审核
    	if(modeId.equals("M_xctcsh"))
    	{
    		return "fengKongShenHe/fkshXctcsh";
    	}
    	//通融区域经理审核
    	if(modeId.equals("M_trqyjlsh"))
    	{
    		return "fengKongShenHe/fkshTrqyjlsh";
    	}
    	
    	//垫款调整B审核
    	if(modeId.equals("M_dktzbsh"))
    	{
    		return "fengKongShenHe/fkshKtzbsh";
    	}
    	return null;
    }
	
	
	/**
	*  风控审核执行列表查询
	*  @author  zhangpp
	*  @Title:  diepuFengKongShenHeV001View  
	*    
	*  @param  @param model
	*  @param  @param busiId
	*  @param  @param replaceId
	*  @param  @param modeId
	*  @param  @return        设定文件  
	*  @return  String        返回类型  
	*  @version  V1.0
	*  @throws
	 */
	@ApiOperation(value = "风控审核执行列表查询", response = Boolean.class, httpMethod="GET", tags={"风控审核执行列表查询"})
    @RequestMapping(value = "diepuFengKongShenHeV001View", method = RequestMethod.GET)
    public String diepuFengKongShenHeV001View(Model model, String busiId,String replaceId,String modeId) throws Exception
	{
    	HttpSession session = request.getSession();      
    	ServletContext  application  = session.getServletContext();  
		String serverRealPath = application.getRealPath("/WEB-INF/configure/fkshConfV001.json");
    	
		JsonParser parse = new JsonParser();  
		JsonObject json = (JsonObject) parse.parse(new FileReader(serverRealPath)); 
		JsonArray  array = json.get("result").getAsJsonArray();
		if(null == array || 0 == array.size())
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"读取审核配置文件为空");
		}
		
		for(int i=0;i<array.size();i++)
		{
			JsonObject object = array.get(i).getAsJsonObject();
			String resultModeId = object.get("modeId").getAsString();
			
			//寻找走向的模板
			if(modeId.equals(resultModeId))
			{
				//特殊处理
				String hrefSwitch = object.get("hrefSwitch").getAsString();
				
				//通用处理
				if(hrefSwitch.equals("FKSHX001"))
				{
					if(StringUtils.isBlank(busiId)) 
			    	{
						ExceptionHelper.thow(ResultFlagType.PARAM_EMPTY);
					}
			    	
			    	model.addAttribute("carCategoryType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_CATEGORY,"请选择..."));
			    	model.addAttribute("carColorType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_COLOR,"请选择..."));
			    	
			    	viewScopeControllerHelper.preparedNowTime(model);
			    	YwBusinessDetail ywBusinessDetail = viewScopeControllerHelper.preparedBusiness(busiId, model);
			    	YwBusinessCar car = viewScopeControllerHelper.preparedCar(busiId, null,model);
			    	if(car != null) {
			    		viewScopeControllerHelper.preparedLoan(busiId, car.getId(), model,car.getCarType());
			    	}
			    	if(ywBusinessDetail != null) {
			    		viewScopeControllerHelper.preparedHistoryBusiness(ywBusinessDetail.getCustomerNo(), model);
			    	}
			    	
			    	viewScopeControllerHelper.preparedRegin(model,null,null);
			    	viewScopeControllerHelper.preparedCarModel(model);
			    	viewScopeControllerHelper.preparedAttachmentEnum(model);
			    	
			    	
			    	//查询待审批列表数据
			    	FkAuditList fkAuditList = new FkAuditList();
			    	fkAuditList.setStatusList(1);
			    	fkAuditList.setBusiId(busiId);
			    	fkAuditList.setModeId(modeId);
			    	fkAuditList.setDpStatus(1);
			    	fkAuditList = fkAuditListMapper.selectRefined(fkAuditList);
			    	
			    	//判断操作人是否与当前的一致
			    	if(null != fkAuditList && !("").equals(fkAuditList))
			    	{
			    		AbstractSysUser currentUser = getCurrentUser();
			    		String id = currentUser.getId();
			    		String name = currentUser.getName();
			    		
			    		String operatorId = fkAuditList.getOperatorId();
			    		if(null == operatorId || ("").equals(operatorId))
			    		{
			    			fkAuditList.setOperatorId(id);
			    			fkAuditList.setOperatorName(name);
			    			fkAuditList.setAcceptDate(new Date());
			    			fkAuditListMapper.updateByPrimaryKeySelective(fkAuditList);
			    		}
			    	}
			    	
			    	//过户信息
			    	if(modeId.equals(ModeIDType.GHSH.getCode()))
			    	{
			    		model.addAttribute("carCategoryType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_CATEGORY,"车辆类别"));
				    	model.addAttribute("carColorType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_COLOR,"车辆颜色"));
			    		YwTransfer ywTransfer = new YwTransfer();
				    	ywTransfer.setBusiId(busiId);
				    	ywTransfer.setDpStatus(1);
				    	ywTransfer = ywTransferMapper.selectRefined(ywTransfer);
				    	model.addAttribute("ywBusinessCar", ywTransfer);
			    	}
			    	
			    	//新车提车
			    	if(modeId.equals(ModeIDType.XCTCSH.getCode()))
			    	{
			    		model.addAttribute("carCategoryType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_CATEGORY,"车辆类别"));
				    	model.addAttribute("carColorType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_COLOR,"车辆颜色"));
				    	DzPickCar dzPickCar = new DzPickCar();
				    	dzPickCar.setBusiId(busiId);
				    	dzPickCar.setDpStatus(1);
				    	dzPickCar = dzPickCarMapper.selectRefined(dzPickCar);
				    	model.addAttribute("ywBusinessCar", dzPickCar);
				    	
//				    	YwBusinessCar ywBusinessCar = new YwBusinessCar();
//				    	ywBusinessCar.setBusiId(busiId);
//				    	ywBusinessCar.setDpStatus(1);
//				    	ywBusinessCar = ywBusinessCarService.selectRefined(ywBusinessCar);
//				    	model.addAttribute("ywBusinessCar", ywBusinessCar);
			    	}
			    	
			    	//查询业务信息表
			    	YwBusiness ywBusinessVo = ywBusinessService.selectById(busiId);
			    	model.addAttribute("ywBusinessVo",ywBusinessVo);
			    	
			    	model.addAttribute("busiId",busiId);
			    	model.addAttribute("replaceId",replaceId);
			    	model.addAttribute("modeId",modeId);
			    	
			    	//下拉选项
			    	model.addAttribute("maritalStatus", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.MARITAL_STATUS,"请选择..."));
			    	model.addAttribute("dealerLevel", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.DEALER_LEVEL,"请选择..."));
			    	model.addAttribute("educationType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.EDUCATION,"请选择..."));
			    	model.addAttribute("sexType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.SEX,"请选择..."));
			    	model.addAttribute("loanType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LOAN_TYPE,"请选择..."));
			    	model.addAttribute("loanBankType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LOAN_BANK,"请选择..."));
			    	model.addAttribute("licencePlateType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LICENCE_PLATE_TYPE,"请选择..."));
			    	model.addAttribute("carType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_TYPE,"请选择..."));
			    	model.addAttribute("carPlaceType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_PLACE,"请选择..."));
			    	model.addAttribute("loanMonthType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LOAN_MONTH,"请选择..."));
			    	model.addAttribute("jobType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.ZHI_WEI,"请选择..."));
			    	model.addAttribute("workAgeType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.WORK_AGE,"请选择..."));
			    	model.addAttribute("carStatus", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_STATUS,"请选择..."));
			    	model.addAttribute("carPurpose", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_PURPOSE,"请选择..."));
			    	model.addAttribute("channelType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CHANNEL_TYPE,"请选择..."));
			    	model.addAttribute("channelStatus", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CHANNEL_STATUS,"请选择..."));
			    	model.addAttribute("busiStatusNames", CachedEnums.getNames(BusiStatus.class));
			    	model.addAttribute("phoneStatusNames", CachedEnums.getNames(PhoneStatus.class));
			    	model.addAttribute("lessInformationStatusNames", CachedEnums.getNames(LessInformationStatus.class));
			    	model.addAttribute("businessExtrasCodeTypeNames", CachedEnums.getNames(BusinessExtrasCodeType.class));
			    	
			    	String hrefUrl = object.get("hrefUrl").getAsString();
					model.addAttribute("hrefUrl",hrefUrl);
					return hrefUrl;
				}
				
				//第二种
				if(hrefSwitch.equals("FKSHX002"))
				{
					model.addAttribute("loanBank", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LOAN_BANK,"请选择..."));
			    	model.addAttribute("carType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_TYPE,"请选择..."));
			    	model.addAttribute("loanType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LOAN_TYPE,"请选择..."));
			    	model.addAttribute("loanMonth", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.LOAN_MONTH,"请选择..."));
			    	model.addAttribute("ccol1", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.INT_TYPE,"请选择..."));
			    	
			    	YwBusinessDetail ywBusinessDetail = viewScopeControllerHelper.preparedBusiness(busiId, model);
			    	if(ywBusinessDetail != null){
			    		viewScopeControllerHelper.preparedYwFee(busiId, ywBusinessDetail.getCustomerId(), model);
			    		viewScopeControllerHelper.preparedFundApply(busiId, ywBusinessDetail.getCustomerId(),null,false, model);
			    		viewScopeControllerHelper.preparedRemitCar(busiId, ywBusinessDetail.getCustomerId(), model);
			    	}
			    	YwBusinessCar car = viewScopeControllerHelper.preparedCar(busiId,ywBusinessDetail.getCustomerId(), model);
			    	if(car != null) {
			    		viewScopeControllerHelper.preparedLoan(busiId, car.getId(), model, car.getCarType());
			    	}
			    	
			    	//车贷信息
			    	YwBusinessLoan ywBusinessLoan = new YwBusinessLoan();
			    	ywBusinessLoan.setBusiId(busiId);
			    	ywBusinessLoan.setDpStatus(1);
			    	ywBusinessLoan = ywBusinessLoanService.selectRefined(ywBusinessLoan);
			    	model.addAttribute("ywBusinessLoan", ywBusinessLoan);
			    	
			    	CwRemitAdjustbSub cwRemitAdjustbSub = new CwRemitAdjustbSub();
			    	cwRemitAdjustbSub.setBusiId(busiId);
			    	cwRemitAdjustbSub.setDpStatus(1);
			    	cwRemitAdjustbSub = cwRemitAdjustbSubService.selectRefined(cwRemitAdjustbSub);
			    	model.addAttribute("cwRemitAdjustbSub", cwRemitAdjustbSub);
			    	
			    	double qyhkcj = 0;
		    		if(null != cwRemitAdjustbSub.getCarPriceNew() && !("").equals(cwRemitAdjustbSub.getCarPriceNew()))
		    		{
		    			if(cwRemitAdjustbSub.getCarPriceNew() > 0)
			    		{
			    			qyhkcj = cwRemitAdjustbSub.getSignLoanAmountNew() / cwRemitAdjustbSub.getCarPriceNew();
			    		}
		    		}
			    	qyhkcj = CommonUtil.getBigDecimal(qyhkcj, 2);
			    	
			    	
			    	double totalRepaymentProportionNew = 0;
			    	if(null != cwRemitAdjustbSub.getCarPriceNew() && null != cwRemitAdjustbSub.getTotalRepaymentAmountNew())
			    	{
			    		if(cwRemitAdjustbSub.getCarPriceNew() > 0)
				    	{
				    		totalRepaymentProportionNew = cwRemitAdjustbSub.getTotalRepaymentAmountNew() / cwRemitAdjustbSub.getCarPriceNew();
				    	}
			    	}
			    	model.addAttribute("totalRepaymentProportionNew", CommonUtil.getBigDecimal(totalRepaymentProportionNew,2));
			    	
			    	
			    	model.addAttribute("qyhkcj", qyhkcj);
			    	double signLoanAmountAdjust = 0;
			    	if(null != cwRemitAdjustbSub.getSignLoanAmountNew() && null != cwRemitAdjustbSub.getSignLoanAmountOld())
			    	{
			    		signLoanAmountAdjust = CommonUtil.getBigDecimal(cwRemitAdjustbSub.getSignLoanAmountNew() - cwRemitAdjustbSub.getSignLoanAmountOld(),2);
			    	}
			    	model.addAttribute("signLoanAmountAdjust", signLoanAmountAdjust);
			    	double loanAmountAdjust = 0;
			    	if(null != cwRemitAdjustbSub.getLoanAmountNew() && null != cwRemitAdjustbSub.getLoanAmountOld())
			    	{
			    		loanAmountAdjust = CommonUtil.getBigDecimal(cwRemitAdjustbSub.getLoanAmountNew() - cwRemitAdjustbSub.getLoanAmountOld(),2);
			    	}
			    	model.addAttribute("loanAmountAdjust", loanAmountAdjust);
			    	
			    	YwFees ywFees = new YwFees();
			    	ywFees.setBusiId(busiId);
			    	ywFees.setDpStatus(1);
			    	ywFees = ywFeesMapper.selectRefined(ywFees);
			    	if(null != ywFees)
			    	{
			    		double rebateDealerAdjust = 0;
			    		if(null != cwRemitAdjustbSub.getRebateDealerNew() && null != ywFees.getRebateDealer())
			    		{
			    			rebateDealerAdjust = CommonUtil.getBigDecimal(cwRemitAdjustbSub.getRebateDealerNew() - ywFees.getRebateDealer(),2);
			    		}
				    	model.addAttribute("rebateDealerAdjust", rebateDealerAdjust);
				    	double rebateProvinceAdjust = 0;
				    	if(null != cwRemitAdjustbSub.getRebateProvinceNew() && null != ywFees.getRebateProvince())
				    	{
				    		rebateProvinceAdjust = CommonUtil.getBigDecimal(cwRemitAdjustbSub.getRebateProvinceNew() - ywFees.getRebateProvince(),2);
				    	}
				    	model.addAttribute("rebateProvinceAdjust", rebateProvinceAdjust);
				    	double rebateAreaAdjust = 0;
				    	if(null != cwRemitAdjustbSub.getRebateAreaNew() && null != ywFees.getRebateArea())
				    	{
				    		rebateAreaAdjust = CommonUtil.getBigDecimal(cwRemitAdjustbSub.getRebateAreaNew() - ywFees.getRebateArea(),2);
				    	}
				    	model.addAttribute("rebateAreaAdjust", rebateAreaAdjust);
			    	}
			 		
			    	
			    	model.addAttribute("busiId",busiId);
			    	model.addAttribute("replaceId",replaceId);
			    	model.addAttribute("modeId",modeId);
			    	
			    	//查询待审批列表数据
			    	FkAuditList fkAuditList = new FkAuditList();
			    	fkAuditList.setStatusList(1);
			    	fkAuditList.setBusiId(busiId);
			    	fkAuditList.setModeId(modeId);
			    	fkAuditList = fkAuditListMapper.selectRefined(fkAuditList);
			    	
			    	//判断操作人是否与当前的一致
			    	if(null != fkAuditList && !("").equals(fkAuditList))
			    	{
			    		AbstractSysUser currentUser = getCurrentUser();
			    		String id = currentUser.getId();
			    		String name = currentUser.getName();
			    		
			    		String operatorId = fkAuditList.getOperatorId();
			    		if(null == operatorId || ("").equals(operatorId))
			    		{
			    			fkAuditList.setOperatorId(id);
			    			fkAuditList.setOperatorName(name);
			    			fkAuditList.setAcceptDate(new Date());
			    			fkAuditListMapper.updateByPrimaryKeySelective(fkAuditList);
			    		}
			    	}
			    	
					String hrefUrl = object.get("hrefUrl").getAsString();
					model.addAttribute("hrefUrl",hrefUrl);
					return hrefUrl;
				}
			}
		}
    	return null;
    }
	
	
	/**
	* 风控审核 资料补齐补审 
	* @author zhangpp
	* @Title: getZiliaobuqiBSListView 
	* 
	* @param @param model
	* @param @param busiId
	* @param @return    设定文件 
	* @return String    返回类型 
	* @version V1.0
	* @throws
	 */
	@ApiOperation(value = "风控审核 资料补齐补审", response = Boolean.class, httpMethod="GET", tags={"风控审核 资料补齐补审"})
    @RequestMapping(value = "getAuditListVoView", method = RequestMethod.GET)
    public String getAuditListVoView(Model model, String busiId) 
	{
    	if(StringUtils.isBlank(busiId)) 
    	{
			ExceptionHelper.thow(ResultFlagType.PARAM_EMPTY);
		}
    	
    	model.addAttribute("carCategoryType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_CATEGORY,"请选择..."));
    	model.addAttribute("carColorType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_COLOR,"请选择..."));
    	
    	viewScopeControllerHelper.preparedNowTime(model);
    	YwBusinessDetail ywBusinessDetail = viewScopeControllerHelper.preparedBusiness(busiId, model);
    	YwBusinessCar car = viewScopeControllerHelper.preparedCar(busiId, null,model);
    	if(car != null) {
    		viewScopeControllerHelper.preparedLoan(busiId, car.getId(), model,car.getCarType());
    	}
    	if(ywBusinessDetail != null) {
    		viewScopeControllerHelper.preparedHistoryBusiness(ywBusinessDetail.getCustomerNo(), model);
    	}
    	viewScopeControllerHelper.preparedRegin(model,null,null);
    	viewScopeControllerHelper.preparedCarModel(model);
    	viewScopeControllerHelper.preparedAttachmentEnum(model);
    	
    	model.addAttribute("busiId",busiId);
    	
    	return "fengKongShenHe/ziliaobuqiBS";
    }
}
